package com.ticket.api.controller;


import com.ticket.api.service.TbUserInfoService;
import com.ticket.api.service.TblMsgContentService;
import com.ticket.common.time.CommonFunction;
import com.ticket.db.entity.TblMsgContent;
import com.ticket.db.entity.TblUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/msg")
public class TblMsgContentController {


    @Autowired
    TblMsgContentService tblMsgContentService;


    @Autowired
    TbUserInfoService userService;

    @GetMapping("/getRecord")
    List<TblMsgContent> findTblMsgContentByCondition( String userId){
        List<TblMsgContent>  listMsg= tblMsgContentService.findByUserId(userId);
        TblUserInfo userInfo =null;
        String idea="";
        for (int i =0;i<listMsg.size();i++){
          listMsg.get(i).setLastUpdateTime(CommonFunction.Toyymmdd(listMsg.get(i).getLastUpdateTime()));
            idea=listMsg.get(i).getUserId1().trim();
            if(idea.equals(userId.trim())){
                idea=listMsg.get(i).getUserId2().trim();
            }
            userInfo=  userService.findTblUserInfoById(idea);

            listMsg.get(i).setUser(userInfo);
        }
return listMsg;
    }
    @RequestMapping("/insertMsg")
    Integer insertTblMsgContent(TblMsgContent content) {
       return tblMsgContentService.insertTblMsgContent(content);
    }
//    Integer  updateTblMsgContent(TblMsgContent content){
//
//    }
}
